<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('labor_attendances', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('company_id')->default(0)->index();
            $table->unsignedBigInteger('project_id')->index()->default(0);
            $table->unsignedBigInteger('team_id')->index()->default(0);
            $table->unsignedBigInteger('labor_company_id')->index()->default(0);
            $table->unsignedBigInteger('labor_id')->index()->default(0);
            // 考勤日期（精确到天）
            $table->date('attendance_date')->comment('考勤日期');
            $table->time('in_time')->nullable()->comment('上班打卡时间');
            $table->time('out_time')->nullable()->comment('下班打卡时间');
            $table->decimal('work_hours', 5, 2)->nullable()->comment('工作时长(小时)');
            $table->string('floor', 100)->nullable()->comment('工作地点');
            $table->string('area', 100)->nullable()->comment('工作区域');
            $table->string('ip', 100)->nullable()->comment('工作ip');
            $table->string('situation', 100)->nullable()->comment('地理位置/经纬度');
            // 考勤状态（枚举类型：正常、迟到、早退、旷工、请假等）
            $table->string('status')->default('normal')->comment('考勤状态：normal-正常，late-迟到，early_leave-早退，absent-旷工，leave-请假');
            // 迟到/早退分钟数（可选）
            $table->unsignedInteger('delay_minutes')->default(0)->comment('迟到分钟数');
            $table->unsignedInteger('early_leave_minutes')->default(0)->comment('早退分钟数');
            // 备注（如请假原因、异常说明）
            $table->string('remark')->nullable()->comment('备注说明');
            // 软删除（可选，用于记录误删的考勤数据）
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('labor_attendances');
    }
};
